//
//  YJHomeViewController.swift
//  微博
//
//  Created by YJW on 16/8/4.
//  Copyright © 2016年 yijiang. All rights reserved.
//

import UIKit


class YJHomeViewController: YJBaseViewController {
    private let cellID = "yijiang"

    //准备微博数据
    private lazy var statusList = [String]()
    
    //加载数据
    override func loadData() {
        
        print("开始刷新 -- \(YJNetworkManager.shared)")
        
        DispatchQueue.main.after(when: DispatchTime.now() + 2) {
            
            for i in 0..<15{
                
                if self.isPullUp{
                    self.statusList.append("\(i) 上拉")
                }else{
                    
                    self.statusList.insert(i.description, at: 0)
                }
                
            }
            
            self.refreshControl?.endRefreshing()
            
            self.tableView?.reloadData()
            
            self.isPullUp = false
            
            print("结束刷新")
        }
        
    }
    
    @objc private func setDemo(){
        let vc = YJDemoViewController()
        //在基类方法中实现隐藏 tabbar 的功能
//        vc.hidesBottomBarWhenPushed = true
        vc.title = "添加好友"
        navigationController?.pushViewController(vc, animated: true)
    }
}

//实现 tableView 的数据源方法
extension YJHomeViewController{
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return statusList.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: cellID)
        
        let cell1 = tableView.dequeueReusableCell(withIdentifier: cellID, for: indexPath)
        
        cell1.textLabel?.text = statusList[indexPath.row]
        
        return cell1
        
    }
}

extension YJHomeViewController{
    
    override func setUpTableView() {

        navigItem.leftBarButtonItem = UIBarButtonItem(name: "添加", target: self, action: #selector(setDemo))
        
        
        super.setUpTableView()
    }
}
